package com.bytecodezz.app.learn3

import android.opengl.GLSurfaceView
import android.util.Log
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class DrawRenderer(private val nativeRenderer: NativeRenderer) : GLSurfaceView.Renderer {
    private val TAG = "DrawRenderer"
    var ptr: Long = 0

    override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?) {
        Log.d(TAG, "onSurfaceCreated()")
        ptr = nativeRenderer.initRenderer()
    }

    override fun onSurfaceChanged(p0: GL10?, width: Int, height: Int) {
        Log.d(TAG, "onSurfaceChanged()")
        nativeRenderer.surfaceChange(ptr, width, height)
    }

    override fun onDrawFrame(gl: GL10?) {
        Log.d(TAG, "onDrawFrame()")
//        GLES20.glClear(GLES20.GL_STENCIL_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
//        GLES20.glClearColor(0.5f, 1, 0.5f, 1);
        //        GLES20.glClear(GLES20.GL_STENCIL_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
//        GLES20.glClearColor(0.5f, 1, 0.5f, 1);
        nativeRenderer.draw(ptr)
    }
}